<!-- 求职意向 -->
<template>
	<view class="jobIntention card">	
		<view class='itemInfo' @click="showsSelect('position')">
			<text>期望职位</text>
			<u-input placeholder="请选择" class="inputBox" border="none" disabled disabledColor="#ffffff" v-model="personInfoData.info.position"></u-input>
		</view>
		<view class='itemInfo' @click="showsSelect('payType')">
			<text>期望薪资类型</text>
			<u-input placeholder="请选择" class="inputBox" border="none" disabled disabledColor="#ffffff" v-model="personInfoData.info.comprehensiveSalaryTypeName"></u-input>
		</view>
		<view class='itemInfo' v-if="personInfoData.info.comprehensiveSalaryType == 1">
			<text>期望月薪起始</text>
			<u-input placeholder="请选择" class="inputBox" border="none"  disabledColor="#ffffff" v-model="personInfoData.info.comprehensiveSalaryStart"></u-input>
		</view>
		<view class='itemInfo' v-if="personInfoData.info.comprehensiveSalaryType == 1">
			<text>期望月薪结束</text>
			<u-input placeholder="请选择" class="inputBox" border="none"  disabledColor="#ffffff" v-model="personInfoData.info.comprehensiveSalaryEnd"></u-input>
		</view>
		<view class='itemInfo' @click="showsSelect('area')">
			<text>求职区域</text>
			<uni-data-picker class="inputBox" v-model="personInfoData.info.address" :localdata="personInfoData.city" popup-title="请选择" :map="{
				text:'name',
				value:'id',
			}" @change="addressChecked">
				<view  :style="{color:'#8E8E93'}">
					{{personInfoData.address?personInfoData.address:'请选择' }}
				</view>
			</uni-data-picker>
			<!-- <u-input placeholder="请选择" class="inputBox" border="none" disabled disabledColor="#ffffff" v-model="personInfoData.sex"></u-input> -->
		</view>
		
		<view class="btnbox">
			<u-button class="custom-style" :plain="true" @click="editFun">保存</u-button>
		</view>
		
		<u-action-sheet
			:show="selectFlag.showSelect"
			:actions="selectFlag.actions"
			class='actionSheet'
			title="请选择"
			description=""
			@close="selectFlag.showSelect = false"
			@select="SelectFun">
		</u-action-sheet>
	</view>
</template>

<script setup lang="ts">
	import { ref,reactive,getCurrentInstance} from 'vue'
	const {proxy} = getCurrentInstance()
	import {useRouter} from 'uni-mini-router'
	let router = useRouter()
	let personInfoData = reactive({
		addressCode:[],
		address:'',
		city:[],
		
		info:{},
		name:'',
		sex:'',
		fileList:[]
	})
	
	let selectFlag = reactive({
		showSelect:false,
		type:'',
		actions:[],
		positionAction:[
			{name: '2000'},
			{name: '2001'},
			{name: '2002'},
			{name: '2003'},
		],
		payActionType:[
			{name:'范围',val:1},
			{name:'面议',val:0}
		],
		payAction:[
			// {name: '2000-3000'},
			// {name: '5000-7000'},
			// {name: '8000-9000'},
			// {name: '9000-13000'},
		],
		areaAction:[
			{name: '北京'},
			{name: '上海'},
		]
	})
	let SelectFun = (e)=>{
		if(selectFlag.type == 'position'){
			personInfoData.info.position = e.name
			personInfoData.info.positionId = e.id
		}else if(selectFlag.type == 'payType'){
			console.log(e,'type')
			personInfoData.info.comprehensiveSalaryType = e.val
			personInfoData.info.comprehensiveSalaryTypeName = e.name	
		}
		// else if(selectFlag.type == 'payType'){
			
		// }
	}
	let showsSelect = (type)=>{
		selectFlag.type = type
		switch (type){	
			case 'position':
				selectFlag.actions = selectFlag.positionAction
				selectFlag.showSelect = true
				break;
			case 'payType':
				selectFlag.actions = selectFlag.payActionType
				selectFlag.showSelect = true
				console.log(selectFlag.actions,'selectFlag.actions')
				break;
			case 'pay':
				selectFlag.actions = selectFlag.payAction
				selectFlag.showSelect = true
				break;
			case 'area':
				// selectFlag.actions = selectFlag.areaAction
				// selectFlag.showSelect = true
				break;
			default:
				break;
		}
	}
	const getAddressTree = () => {
		uni.showLoading({})
		//获取地区
		proxy.$req('GET', proxy.$api.getAddressTree, {}).then((res) => {
			uni.hideLoading()
			console.log(res.result,'list')
			personInfoData.city = res.result
		})
	}
	getAddressTree()
	
	const addressChecked = (e) => {
		//选择地址
		console.log(e,'选择地址');
		personInfoData.addressCode = e.detail.value
		// console.log(personInfoData.addressCode,'personInfoData.addressCode')
		personInfoData.address = e.detail.value[0].text + e.detail.value[1].text + e.detail.value[2].text
		// addressThree.value = e.detail.value
		// formA.value.address = e.detail.value[0].text + e.detail.value[1].text + e.detail.value[2].text
	}
	
	// 获取个人简历详情
	const meiyeRecruitHunterInfo2DetailsFun = ()=>{
		//获取详情
		proxy.$req('GET', proxy.$api.meiyeRecruitHunterInfo2Details).then((res) => {
			if(res.code === 200){
				console.log(res.result.comprehensiveSalaryType,res.result.comprehensiveSalaryType!=null && res.result.comprehensiveSalaryType!=''&& res.result.comprehensiveSalaryType!=undefined)
				if(res.result.comprehensiveSalaryType!==null && res.result.comprehensiveSalaryType!==''&& res.result.comprehensiveSalaryType!==undefined){
					let idx = selectFlag.payActionType.findIndex(el=>el.val == res.result.comprehensiveSalaryType)
					if(idx!=-1){
						res.result.comprehensiveSalaryTypeName = selectFlag.payActionType[idx].name
					}
				}else{
					res.result.comprehensiveSalaryTypeName = ''
				}
	
				personInfoData.info = res.result
				personInfoData.address = personInfoData.info.address
				personInfoData.addressCode= [
					{text:personInfoData.info.provinceName,value:personInfoData.info.provinceId},
					{text:personInfoData.info.cityName,value:personInfoData.info.cityId},
					{text:personInfoData.info.areaName,value:personInfoData.info.areaId},
				]
				
			}
		})
	}
	
	// 修改数据
	const editFun = ()=>{
		if(personInfoData.addressCode.length>0){
			personInfoData.info.provinceName = personInfoData.addressCode[0].text
			personInfoData.info.provinceId = personInfoData.addressCode[0].value	
			personInfoData.info.cityName = personInfoData.addressCode[1].text
			personInfoData.info.cityId = personInfoData.addressCode[1].value
			personInfoData.info.areaName = personInfoData.addressCode[2].text
			personInfoData.info.areaId = personInfoData.addressCode[2].value
			personInfoData.info.address = personInfoData.address
		}
		proxy.$req('POST', proxy.$api.meiyeRecruitHunterInfo2edit,personInfoData.info).then((res) => {
			if(res.code === 200){
				router.push({
					name: 'onlineResume'
				})
			}
		})
	}
	
	//获取招聘分类
	const getZpClassify = () => {
		proxy.$req('GET', proxy.$api.getRecruitmentTypeList, {}).then((res) => {
			console.log(res);
			if(res.code === 200){
				selectFlag.positionAction = res.result
			}
		})
	}
	getZpClassify()
	meiyeRecruitHunterInfo2DetailsFun()
</script>
<style lang="scss" scoped>
	page{
		background:#f6f6f6;
		padding:30rpx;
	}
	.actionSheet{
		max-height:1000rpx;
		overflow-y: auto;
	}
	.jobIntention{
	
		.itemInfo{
			display:flex;
			justify-content: space-between;
			// flex-direction: column;
			// align-items: center;
			padding:30rpx 0;
			border-bottom: 1rpx solid #eee;
			text{
				color: rgba(0, 0, 0, 1);
				font-size: 32rpx;
				padding-bottom:20rpx;
				
			}
			:deep(.inputBox){
				background-color:#fff;
				.uni-input-input,.uni-input-placeholder,.uni-data-tree-input{
					text-align: right !important;
					color:#8E8E93;
					font-size:30rpx;
				}
				
			} 
		}
		
		.btnbox{
			padding:100rpx 0rpx;
			
			.custom-style {
				color: #fff;
				background-color: rgba(203, 100, 94, 1);
				width: 80%;
				border-radius: 14rpx;
			}
		}
	}
	
	.card{
		background:#fff;
		box-sizing: border-box;
		border: 2rpx solid #fff;
		margin: 30rpx auto;
		padding: 24rpx;
		background:#fff;
		border-radius: 24rpx;
		box-shadow: 8rpx 8rpx 32rpx 0rpx rgba(0, 0, 0, 0.04);
	}
</style>